//
//  MainViewController.swift
//  Weibo
//
//  Created by gdarkness on 16/3/20.
//  Copyright © 2016年 gdarkness. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.setValue(MainTabBarView(), forKey: "tabBar")
        
        addChildViewControllers()
        
        //设置tabBar控制器的子控制器
        //首页
           }
    func addChildViewControllers(){
        let homeControl =  HomeViewController()
        addChildViewController(homeControl, title: "主页", imageName: "tabbar_message_center")
        //消息
        let messageControl = MessageViewController()
        addChildViewController(messageControl, title: "消息", imageName: "tabbar_message_center")
        //发现
        let discoverControl = DiscoverViewController()
        addChildViewController(discoverControl, title: "发现", imageName: "tabbar_discover")
        //我
        let profileControl = ProfileViewController()
        addChildViewController(profileControl, title: "我", imageName: "tabbar_profile")

    }
        func addChildViewController(controller : UIViewController ,title : String ,imageName : String){
            //设置标题
            controller.title = title
            //设置图片
            controller.tabBarItem.image = UIImage(named: imageName)
            //拼接高亮图片
            let hightedImageName = imageName + "_highlighted"
            //设置高亮图片
            controller.tabBarItem.selectedImage = UIImage(named: hightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            
            //设置item 的文字颜色
            controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
            
            //添加子控件
            addChildViewController(UINavigationController(rootViewController: controller))
            
        }
    }

